package annimation.com.junge.annimation;

import java.lang.reflect.Method;



import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import annimation.com.junge.entity.User;
import annimation.com.junge.service.UserService;

@Component
@Aspect
public class LoggerAop {
	 @Autowired
	    UserService service;
	@Pointcut("@annotation(annimation.com.junge.annimation.Loge)")
	public void annimation(){
		
	}
	@Before("annimation()")
	public void time(){
		System.err.println("++++++kaishi");
	}
	
	@Around("annimation()")
	public Object around(ProceedingJoinPoint joinPoint) throws Throwable{
		Object ob=null;
		ob=joinPoint.proceed();
		return ob;
	}
	@After("annimation()")
    public void before(JoinPoint joinPoint){
	       MethodSignature sign =  (MethodSignature)joinPoint.getSignature();
	       Method method = sign.getMethod();
	       Loge annotation = method.getAnnotation(Loge.class);
	       System.out.print("打印："+annotation.value()+" 前置日志");
	       User u=new User();
	       u.setPassWord(annotation.value());
	       u.setStatus(1);
	       u.setEmail("zjzjzjz");
	       u.setUserName("121qwq");
	       service.insert(u);
	    }
	
}
